export default {
  // 用户登录管理自己信息的仓库
  
  state: {
    // 是否编辑用户基本信息
    isEditUserBasicInfo: false,
    // 是否编辑用户求职状态
    isEditUserJobState: false,
    // 是否编辑用户求职意愿
    isEditUserJobIdens: false,
    // 是否编辑用户教育经历
    isEditUserEdu: false,
    // 是否编辑用户工作经历
    isEditUserJobEx: false,
    // 是否编辑用户项目经验
    isEditUserProjectEx: false,
    // 是否编辑用户荣誉奖项
    isEditUserHonors: false,
    // 是否编辑用户自我评价
    isEditUserSelfEvaluation: false,

    // 用户基本信息
    userBasicInfo: {
      avatar: "",
      gander: "",
      name: "",
      birth: "",
      birthAddress: ['', ''],
      newAddress: ["", ""],
      graduateTime: "",
      // 政治身份
      politicalOutlook: "",
      phone: "",
      email: "",
    },
    // 用户求职状态
    
    userJobState: "",
    // 用户求职意向
    userJobIdens: {
     
      title: "",
      salaryMin: "",
      salaryMax: "",
      city: ["", ""],
      jobNature: "",
      industry: ["",""]
    },
    // 用户教育经历
    userEdu: {
      
      schoolName: "",
      education: "",
      major: "",
      schoolTime: ["", ""],
      eduMajorDetail:""
    },

    // 用户工作经历
    
    userJobEx:{
      jobExTime:[],
      jobExEnterprise:"",
      jobExLevel:"",
      jobExDetail:""
    },
    // 用户项目经验
    
    userProjectEx:{
      projectTime:[],
      projectEnterprise:'',
      projectName:"",
      projectDetail:""
    },
    // 用户荣誉奖项
    
    userHonors:[],
    userSelfEvaluation:`` ,
    // 用户已申请的工作
    userApplyJobs: [],
    // 用户已收藏的工作
    userCollectionJobs: [],

    // 申请收藏
    users:[],
    // 申请
    jobIndustryArr:[],
    eNameArr:[],
    applyStateArr:[],

  },
  mutations: {
    upUserBasicInfo(state: any, newUserIfo: any) {
      state.userBasicInfo.name = newUserIfo.name
      state.userBasicInfo.gander = newUserIfo.gander
      state.userBasicInfo.birth = newUserIfo.birth
      state.userBasicInfo.birthAddress = newUserIfo.birthAddress
      state.userBasicInfo.newAddress = newUserIfo.newAddress
      state.userBasicInfo.politicalOutlook = newUserIfo.politicalOutlook
      state.userBasicInfo.phone = newUserIfo.phone
      state.userBasicInfo.email = newUserIfo.email
    },
    upJobState(state: any, newJobState: string) {
      state.userJobState = newJobState
    },
    upUserJobIden(state: any, newJobIden: any) {
      state.userJobIdens.title = newJobIden.title
      state.userJobIdens.salaryMax = newJobIden.salaryMax
      state.userJobIdens.salaryMin = newJobIden.salaryMin
      state.userJobIdens.city = newJobIden.city
      state.userJobIdens.jobNature = newJobIden.jobNature
      state.userJobIdens.industry = newJobIden.industry
    },
    upUserEdu(state: any, newEdu: any) {
      state.userEdu.schoolName = newEdu.schoolName
      state.userEdu.education = newEdu.education
      state.userEdu.major = newEdu.major
      state.userEdu.schoolTime = newEdu.schoolTime
      state.userEdu.eduMajorDetail = newEdu.eduMajorDetail
    },

    upUserCollectionJobs(state:any,row:any){
      state.userCollectionJobs.forEach((value:any,index:any,self:any)=>{
        if(value.eId==row.eId && value.jobId==row.jobId){
          state.userCollectionJobs.splice(index,1)
        }
      })
    },

    upUserJobEx(state: any, newJobEx:any) {
      state.userJobEx.jobExTime = newJobEx.jobExTime
      state.userJobEx.jobExEnterprise = newJobEx.jobExEnterprise
      state.userJobEx.jobExLevel = newJobEx.jobExLevel
      state.userJobEx.jobExDetail = newJobEx.jobExDetail
    },
    upUserProjectEx(state: any, newProjectEx: any) {
      state.userProjectEx.projectTime = newProjectEx.projectTime
      state.userProjectEx.projectEnterprise = newProjectEx.projectEnterprise
      state.userProjectEx.projectName = newProjectEx.projectName
      state.userProjectEx.projectDetail = newProjectEx.projectDetail
    },
    upUserHonors(state: any, newHonors: any) {
      state.userHonors = newHonors
    },
    upUserSelfEvaluation(state: any, newSelfEvaluation: string) {
      state.userSelfEvaluation = newSelfEvaluation
    },

    upUserPhone(state:any,phone:string){
      state.userBasicInfo.phone=phone
    },
    upUserEmail(state:any,email:string){
      state.userBasicInfo.email=email
    },

    // 修改申请状态
    // upUserApply(state:any){
    //   console.log(state);
      
    // },



    // 编辑基本信息
    editBasicUserInfo(state: any) {
      state.isEditUserBasicInfo = !state.isEditUserBasicInfo
    },
    // 编辑求职状态
    editJobState(state: any) {
      state.isEditUserJobState = !state.isEditUserJobState
    },
    // 编辑求职意向
    editJobIden(state: any) {
      state.isEditUserJobIdens = !state.isEditUserJobIdens
    },
    // 编辑教育经历
    editEdu(state: any) {
      state.isEditUserEdu = !state.isEditUserEdu
    },
    // 编辑工作经历
    editJobEx(state: any) {
      state.isEditUserJobEx = !state.isEditUserJobEx
    },
    // 编辑项目经验
    editProjectEx(state: any) {
      state.isEditUserProjectEx = !state.isEditUserProjectEx
    },
    // 编辑荣誉奖项
    editHonors(state: any) {
      state.isEditUserHonors = !state.isEditUserHonors
    },
    // 编辑自我评价
    editSelfEvaluation(state: any) {
      state.isEditUserSelfEvaluation = !state.isEditUserSelfEvaluation
    },

    // 申请
    setUsersArr(state:any,arr:any){
      state.users=arr
    },
    setApplyStateArr(state:any,arr:any){
      state.applyStateArr=arr
    },
    setENameArr(state:any,arr:any){
      state.eNameArr=arr
    },
    setJobIndustryArr(state:any,arr:any){
      state.jobIndustryArr=arr
    },


  },
  getters: {

    getAge(state: any) {
      // 计算年龄
      const birth = state.userBasicInfo.birth
      const nowData = new Date()
      const birthArr = birth.split("-")
      const year = parseInt(birthArr[0])
      const mouth = parseInt(birthArr[1])

      let age
      if (nowData.getMonth() - mouth < 0) {
        age = nowData.getFullYear() as any - year - 1
      } else {
        age = nowData.getFullYear() as any - year
      }
      if (age < 0) age = 0
      return age
    },

    getSchoolTime(state: any) {
      // console.log(state.userEdu.schoolTime);
      
      if(state.userEdu.schoolTime[0]!="" && state.userEdu.schoolTime[1]!=""){
        return state.userEdu.schoolTime[0] + "-" + state.userEdu.schoolTime[1]
      }
      
    },
    getJobEXTime(state: any) {
      if(state.userJobEx.jobExTime[0] && state.userJobEx.jobExTime[1]){
        return state.userJobEx.jobExTime[0] + "-" + state.userJobEx.jobExTime[1]
      }
      
    },
    getProjectEXTime(state: any) {
      if(state.userProjectEx.projectTime[0] && state.userProjectEx.projectTime[1]){
        return state.userProjectEx.projectTime[0] + "-" + state.userProjectEx.projectTime[1]
      }
      
    },
    getGraduateTime(state: any) {
      const graduateTime = state.userEdu.schoolTime[1]
      const graduateTimeArr = graduateTime.split(".")
      const time = graduateTimeArr[0].substring(graduateTimeArr[0].length - 2)
      return time

    },
    getAddress(state: any) {
      if (state.userBasicInfo.birthAddress[0] == "重庆市" || state.userBasicInfo.birthAddress[0] == "上海市" || state.userBasicInfo.birthAddress[0] == "北京市" || state.userBasicInfo.birthAddress[0] == "天津市") {
        return state.userBasicInfo.birthAddress[0]
      } else {
        return state.userBasicInfo.birthAddress[1]
      }
    }

  }

}